package com.fita.wechat.dto;

import java.beans.Transient;

import javax.persistence.EnumType;
import javax.persistence.Enumerated;

import org.apache.commons.lang3.StringUtils;

import com.fita.entity.agent.AgentApply;
import com.fita.entity.agent.AgentType;
import com.fita.entity.principal.District;

/**
 * 
 * @author 宋剑宏
 *
 */
public class AgentApplyRequest {
    
    private String email;
    
    private String alias;
    
    private String name;
    
    private String mobile;
    
    private Long districtId;
    
    @Enumerated(EnumType.STRING)
    private AgentType type;
    
    private String companyName;
    
    private String companyAddress;

    /**
     * 一级代理ID
     */
    private Long primaryAgentId;

    /**
     * 代理提成比例
     */
    private Integer rate;

    /**
     *
     */
    public AgentApplyRequest() {
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public boolean validate() {
        // 判断必填字段是否为空
        boolean result = (this.type != null) && 
                         StringUtils.isNotBlank(this.name) &&
                         StringUtils.isNotBlank(this.email) &&
                         StringUtils.isNotBlank(this.mobile) &&
                         (districtId != null);
        
        // 若为公司代理公司名称不可为空
        if(result) {
            if(this.type.isCompany()) {
                result = StringUtils.isNotBlank(this.companyName);
            }
        }
        
        return result;
    }
    
    /**
     * 
     * @param district
     * @return
     */
    @Transient  
    public AgentApply generateAgentApply(District district) {
        AgentApply agentApply = new AgentApply();
        
        agentApply.setName(this.name);
        agentApply.setEmail(this.email);
        agentApply.setMobile(this.mobile);
        agentApply.setType(this.type);
       
        agentApply.setCompanyName(this.companyName);
        agentApply.setDistrict(district);
        return agentApply;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @return the alias
     */
    public String getAlias() {
        return alias;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the mobile
     */
    public String getMobile() {
        return mobile;
    }

    /**
     * @return the districtId
     */
    public Long getDistrictId() {
        return districtId;
    }

    /**
     * @return the type
     */
    public AgentType getType() {
        return type;
    }

    /**
     * @return the companyName
     */
    public String getCompanyName() {
        return companyName;
    }

    /**
     * @return the companyAddress
     */
    public String getCompanyAddress() {
        return companyAddress;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @param alias the alias to set
     */
    public void setAlias(String alias) {
        this.alias = alias;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param mobile the mobile to set
     */
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    /**
     * @param districtId the districtId to set
     */
    public void setDistrictId(Long districtId) {
        this.districtId = districtId;
    }

    /**
     * @param type the type to set
     */
    public void setType(AgentType type) {
        this.type = type;
    }

    /**
     * @param companyName the companyName to set
     */
    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    /**
     * @param companyAddress the companyAddress to set
     */
    public void setCompanyAddress(String companyAddress) {
        this.companyAddress = companyAddress;
    }

    public Long getPrimaryAgentId() {
        return primaryAgentId;
    }

    public void setPrimaryAgentId(Long primaryAgentId) {
        this.primaryAgentId = primaryAgentId;
    }

    public Integer getRate() {
        return rate;
    }

    public void setRate(Integer rate) {
        this.rate = rate;
    }
}
